<?php if (!defined('THINK_PATH')) exit();?><script type="text/javascript" src="/viner/Public/js/jquery-barcode.js"></script>
<!-- <link rel="stylesheet" type="text/css" media="print3" href="/viner/Public/css/myJqPrint3.css" /> -->

<style type="text/css">
	.printvin{
	    padding: 15px 5px 15px 5px;
    width: 96%;
    border: 1px solid #999;
    margin: 2px 2px 2px 2px;
}

.hl{
    font-size: 16px;
    float: left;
    
}
.hr{
    font-size: 16px;
    float: right;
}
.vinbar{
	padding:3px 0 3px 0;
}
.breakline{

}
</style>
<div id="cc" class="easyui-layout" data-options="fit:true">   
  
    <!-- <div data-options="region:'south',title:'计划描述',split:true" style="height:100px;"></div>    -->
    
    <!-- <div data-options="region:'west',title:'West',split:true" style="width:100px;"></div>    -->
    <div data-options="region:'center',title:'',border:false" style="padding:0px;">

    	<table id="dg_vin"></table>
    </div>  
        <div data-options="region:'east',iconCls:'icon-reload',title:'VIN码打印',split:true" style="width:450px;">
	        <div id="printTool" class='datagrid-toolbar'>
	    		<a href="#"  onclick='print_vin()' class="easyui-linkbutton" data-options="iconCls:'icon-standard-printer'">打印</a> 
	    	</div>
	    	<!-- 打印预览区域 -->
    	<div id="vinPrintAra"></div>
        </div>   
</div> 
<div id="tool_vin">
	

	<table>
		<tr>
			<td>
				流水号：<input id="vin_lsh" name="lsh" class="easyui-textbox" data-options="prompt:'请输入单个流水号…'" style="width:100px"> 
				装配计划号：<input id="zpjh" name="zpjh" class="easyui-textbox" data-options="" style="width:100px"> 
				计生号：<input id="jsh" name="jsh" class="easyui-textbox" data-options="" style="width:100px"> 
				
				<a href="#" class="easyui-linkbutton"  onclick="search_vin()" data-options="iconCls:'icon-search',plain:'true'">搜索</a> 
			</td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<!-- <td>
				<a href="#" class="easyui-linkbutton"  onclick="print_vin()" data-options="iconCls:'icon-search',plain:'true'">打印</a>
			</td> -->
			<td>

				<a href="#" class="easyui-linkbutton"  onclick="reload_vin()" data-options="iconCls:'icon-standard-arrow-refresh',plain:true"></a> 

			</td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
		</tr>
	</table>
</div>
<script type="text/javascript">
function print_vin(){
$('#vinPrintAra').jqprint(
		media="print3"
		);
}
function search_vin(){
		// 获取over的状态

		$('#dg_vin').datagrid('load',{
			 zpjh:$('#zpjh').textbox('getText'),
			lsh:$('#vin_lsh').textbox('getText'),
			zpjh:$('#zpjh').textbox('getText')
			 });


	}
	  function reload_vin() {
		$('#dg_vin').datagrid('reload', {   
		    lsh: '' 
		});
	}


	$('#dg_vin').datagrid({
	url : '/viner/index.php/Home/Vin/read',
	toolbar : '#tool_vin',
	pagination : true,
	fit : true,
	width : function() {
		return document.body.clientWidth * 0.9
	},
	nowrap : true,//
	collapsible : true,
	fitColumns : false,
	autoRowHeight : false,
	striped : true,//交替行
	singleSelect : false,//只允许选择一行
	rownumbers : true,
	border : false,
	sortName : 'id',
	sortOrder : 'desc',//倒序排列
	remoteSort : false,
	pageSize : 30,
	method : "post",
	pageList : [ 10, 15, 30, 40, 50, 100, 200 ,500,1000],
	columns : [ [
			{
				field : 'id',
				checkbox : true
			},{
				field : 'zpjh',
				title : '装配计划',
				width : 120
			},
			{
				field : 'cx',
				title : '出具车型',
				width : 150
			},

			{
				field : 'vin',
				title : 'VIN码',
				width : 180
			},
			{
				field:'lsh',
				title:'流水号'
			},
			{
				field : 'num',
				title : '数量',
				width : 60
			}, {
				field : 'rwh',
				title : '任务号',
				width : 180,
				align : 'left'
			}
, {
				field : 'jsh',
				title : '计生号',
				width : 120,
				align : 'left'
			}


	] ],
	  onDblClickRow: function (rowIndex, rowData) { 
	  	// console.log(rowData);


	
	  },
	    onSelect:function(index,row){

		        	addvinDiv(row);
		        
		        	
		    },
		    onUnselect:function(index,row){
		    	delvinDiv(row);
		    },
		     onSelectAll:function(rows){
// $('#dg_vin').datagrid('unselectAll');
	// console.log(rows);
		     	
		    	for (var i = 0; i < rows.length; i++) {
		    		addvinDiv(rows[i],2);
		    	}
		    },
		     onUnselectAll:function(rows){
	    	    $.messager.confirm('确认','您确认想要取消所有已经选取的VIN码吗？',function(r){    
		            if (r){    
		                $("#vinPrintAra").html(""); 
		            }    
    			}); 
		    }



});
	/**
 * [nowData 当前日期]
 * @return {[type]} [description]
 */
  function nowData(){
    var mydate = new Date();
    var str = "" + mydate.getFullYear() + "年";
    str += (mydate.getMonth()+1) + "月";
    str += mydate.getDate() + "日";
    return str;
   }

	function addvinDiv(row,d=1){
var div=$("#print_vin_"+row.lsh);
// var sjjhh=$('#sjjhh').val();
// var rwh=$('#rwh').val();
// var tf=$('#tf').val();
if(div.length>0){
	if(d==1){
		$.messager.alert('数据', '已经存在', 'info');
	}
		  	
	}else{

		var string='<div id="print_vin_'+row.lsh+'" class="printvin">'+
							'	<div style="display:inline;">'+
							'		<div class="hl">'+row.rwh+'</div>'+
							'		<div class="hr"">'+row.vin+'</div>'+
							'	</div>'+
							'	<div class="vinbar" id="bar_'+row.lsh+'">asdad</div>'+
							'	<div style="display:inline;float:none;">'+
							'		<div class="hl">'+row.jsh+'</div>'+
							'		<div class="hr">'+row.vin+'</div>'+
							'	</div></div>';


							string+='<div class="breakline" id="break_vin_'+row.lsh+'" style="page-break-after:always"></div>';

						
			
	

		$('#vinPrintAra').append(string);	
		$("#bar_"+row.lsh).empty().barcode(row.vin, "code128",{barWidth:2, barHeight:35,showHRI:false});
}

	

}

 
function delvinDiv(row){
var div=$("#print_vin_"+row.lsh);
var b=$("#break_vin_"+row.lsh);
if(div.length>0){
	div.remove();
	b.remove();
}else{

}
}

</script>